package com.xiukelai.springboot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiukelai.springboot.base.BaseController;
import com.xiukelai.springboot.entity.SysProduct;
import com.xiukelai.springboot.service.ISysProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 存储商品信息：系统后台维护 前端控制器
 * </p>
 *
 * @author hutao
 * @since 2019-07-26
 */
@RestController
@RequestMapping(value = "/springboot/sysProduct")
public class SysProductController extends BaseController {

    @Autowired
    private ISysProductService sysProductService;

    @GetMapping(value = "/list")
    public String list(@RequestParam Map map){
        List<SysProduct> list=this.sysProductService.list();
        for(SysProduct e:list){
            System.out.println(e);
        }
        return list.toString();
    }

    @GetMapping(value = "/page")
    public String page(@RequestParam Map map){
        Page<SysProduct> page=this.getPage(0l,10l);
        this.sysProductService.page(page);
        for(SysProduct e:page.getRecords()){
            System.out.println(e);
        }
        return callbackSuccess(page);
    }

    @GetMapping(value = "insert")
    public Boolean insert(@RequestParam Map map){
        SysProduct sysProduct=new SysProduct();
        Integer i = (int) ((Math.random() * 9 + 1) * 100000);
        sysProduct.setId(Long.valueOf(i.toString()));
        sysProduct.setName("i"+i+"产品");
        sysProduct.setConponType(1);
        sysProduct.setIconUrl("/a/ab/a");
        sysProduct.setLimitPrice(BigDecimal.valueOf(2.36));
        sysProduct.setMarketPrice(BigDecimal.valueOf(6.36));
        sysProduct.setTopPrice(BigDecimal.valueOf(9.87));
        Integer j = (int) ((Math.random() * 9 + 1) * 100000);
        sysProduct.setProductTypeId(Long.valueOf(j.toString()));
        return this.sysProductService.save(sysProduct);
    }


    //日志系统测试



}

